package DAY1209.Demo1;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

/**
 * @Author:LiRegin
 * @Date: 2019/12/9 15:05:53
 */
public class Test {
    public static void main(String[] args) throws Exception {
        SAXReader reader = new SAXReader();
        Document dom = reader.read(new File("C:\\XML\\src\\DAY1209\\Demo1\\city.xml"));
        Element root = dom.getRootElement();
        List<Element> servletList = root.elements("city");
        System.out.println("cityid:"+servletList.get(0).attributeValue("id"));
        for(Element servlet:servletList){
            List<Element> elements=servlet.elements();
            for (Element element : elements) {
                System.out.println(element.getName()+":"+element.getText());
            }
        }
    }
}
